使用@ConfigurationProperties注入


https://www.baeldung.com/configuration-properties-in-spring-boot

  1. transfor to 1 Dto

來源:以下這些格式都映射為hostName

mail:
  hostName: server
  hostname: server
  host_name: server
  host-name: server
  HOST_NAME: server
@Configuration
@EnableConfigurationProperties(ConfigProperties.class)
@ConfigurationProperties(prefix = "mail")
public class ConfigProperties {

    private String hostName;
    private int port;
    private String from;

    // standard getters and setters
}
  1. transfor to many Dto
    (其他)透過yml設定檔注入參數至特定資料結構

這不是一個給新手的一個教學過程,也寫的不是很完整
希望大家多多包涵囉~
主要是給自己的一個紀錄,也分享給有需要的夥伴
這是一個心血來潮,產生的文章
若有喜歡或交流的部分都歡迎在下方留言,多多關照。

##attribute ##spring







你可能感興趣的文章

JS try catch 使用方式

JS try catch 使用方式

[JS Behind The Scene] 從簡單例子了解 hoisting 的運作機制

[JS Behind The Scene] 從簡單例子了解 hoisting 的運作機制

很重要的基礎-檔案格式

很重要的基礎-檔案格式






留言討論